﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Pheonix.CodeLibrary.Web;

public partial class page_public_shopdetail : BasePage
{
    private int shopId;
    protected void Page_Load(object sender, EventArgs e)
    {
        Title = SiteName + " - Shop Detail"; 

        if (!IsPostBack)
        {
            if (!String.IsNullOrEmpty(Request["id"]))
            {
                if (!Int32.TryParse(Request["id"], out shopId))
                    shopId = 0;
            }
            else
                shopId = 0;

            InitPage();
        }
    }

    protected void Page_LoadComplete(object sender, EventArgs e)
    {
        LoadData();
    }

    private void InitPage()
    {
        DataTable shopData = ShopManager.GetShopDetail(shopId);
        if (shopData.Rows.Count > 0)
        {
            shopName.Text = shopData.Rows[0]["shop_name"].ToString();
            shopLogo.ImageUrl = shopData.Rows[0]["shop_logo_path"].ToString();
            shopCode.Text = shopData.Rows[0]["shop_code"].ToString();
            brandAddress.Text = shopData.Rows[0]["branch_address"].ToString();
            emailAddress.Text = shopData.Rows[0]["email"].ToString();
            phoneNumber.Text = shopData.Rows[0]["phone"].ToString();
            rating.Text = shopData.Rows[0]["rating"].ToString();
            views.Text = shopData.Rows[0]["total_visit"].ToString();
            categories.Text = shopData.Rows[0]["category_count"].ToString();
        }
    }

    private void LoadData()
    {
        DataTable searchResult = new DataTable();

        searchResult = ShopManager.GetShopNewProducts(shopId);

        productList.DataSource = searchResult;
        productList.DataBind();

        DataTable shopCategory = new DataTable();

        shopCategory = ShopManager.GetShopCategoryList(shopId);

        categoryList.DataSource = shopCategory;
        categoryList.DataBind();

    }
}
